package com.toilet.easyvideofx.service.impl;

import com.toilet.easyvideofx.domain.DownloadFileRecord;
import com.toilet.easyvideofx.mapper.DownloadFileRecordMapper;
import com.toilet.easyvideofx.service.DownloadFileService;
import com.toilet.easyvideofx.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class DownloadFileServiceImpl implements DownloadFileService {
    @Override
    public List<DownloadFileRecord> selectPage(int page, int size) {
        List<DownloadFileRecord> records = new LinkedList<>();
        try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
            DownloadFileRecordMapper recordMapper = sqlSession.getMapper(DownloadFileRecordMapper.class);
            records = recordMapper.selectPage(page, size);
        } catch (Exception e) {
            System.out.println("查询异常:" + e);
        }
        return records;
    }

    @Override
    public int insertRecord(DownloadFileRecord downloadFileRecord) {
        try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
            DownloadFileRecordMapper recordMapper = sqlSession.getMapper(DownloadFileRecordMapper.class);
            int record = recordMapper.insertRecord(downloadFileRecord);
            sqlSession.commit();
            return record;
        } catch (Exception e) {
            System.out.println("查询异常:" + e);
        }
        return 0;
    }
}
